perm filename A44[106,RWF] blob sn#790298 filedate 1985-03-11 generic text, type C, neo UTF8
COMMENT āŠ—   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	I want to save my money to buy a sailboat, and sail away to Tahiti. I have
C00004 ENDMK
CāŠ—;
I want to save my money to buy a sailboat, and sail away to Tahiti. I have
a modest initial bank balance (call it FIRSTBAL). At the beginning of each
year I deposit a fixed amount (DEPOSIT); at the end of the year, the bank
pays me interest, multiplying my deposit by 1+RATE. The boat costs BOATPRICE.
A program to determine how many years are required is:

READ(FIRSTBAL, DEPOSIT, RATE, BOATPRICE);
BALANCE:= FIRSTBAL;
COUNT:= 0
WHILE BALANCE<BOATPRICE DO
	BEGIN
	BALANCE:= BALANCE+DEPOSIT;
	BALANCE:= BALANCE*(1+RATE);
	COUNT:= COUNT+1   (* ONE YEAR HAS PASSED *)
	END;
WRITE ('YOU MUST WORK', COUNT, 'YEARS FOR YOUR BOAT')
END.

Again, the program above works correctly even when the answer is zero;
because it tests before executing the body of the iteration, it is able
to skip the body entirely.

(Note to instructor: if your students insist on using REPEAT, show them
why it fails here when the answer is zero.)